<?php

if (!defined('PATH_BASE')) {
	define('PATH_BASE', dirname(dirname(dirname(dirname(__FILE__)))));
}

require_once(PATH_BASE . '/app/config/App.php');

function callWebService($protocol, $controller, $action, $payload = '') {
	$url = API_URL . "/{$protocol}/{$controller}/{$action}";
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 4);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	$result = curl_exec($ch);
	$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	if ($httpStatus == 500) {
		$result = strip_tags($result);
	}
	return $result;
}
